package com.sevattal.service.leaves.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sevattal.service.leaves.entity.EmpAuthority;
import com.sevattal.service.leaves.entity.vo.EmpAuthorityVo;
import com.sevattal.service.leaves.mapper.EmpAuthorityMapper;
import com.sevattal.service.leaves.service.EmpAuthorityService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmpAuthorityServiceImpl extends ServiceImpl<EmpAuthorityMapper, EmpAuthority> implements EmpAuthorityService {
    @Override
    public List<EmpAuthorityVo> getByEmpId(String id) {
        List<EmpAuthorityVo> empAuthorityVoList = baseMapper.selectByEid(id);
        return empAuthorityVoList;
    }

    @Override
    public boolean authEmp(List<EmpAuthority> empAuthorityList) {
        QueryWrapper<EmpAuthority> queryWrapper = new QueryWrapper<>();
        for (int i=0;i<empAuthorityList.size();i++){
            queryWrapper.eq("f_aId",empAuthorityList.get(i).getFAid()).eq("f_eId",empAuthorityList.get(i).getFEid());
            int count = baseMapper.selectCount(queryWrapper);
            if (count == 1) {
                continue;
            }
            baseMapper.insert(empAuthorityList.get(i));
            queryWrapper.clear();
        }
        return true;
    }
}
